package com.example.consult.mapper;

import com.example.consult.model.QuestionTable;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface QuestionMapper {
    /*
    查询点击率最高的问题
     */
    @Select("select * from question_table where classify_level=${2} order by click_time desc limit 5")
    public List<QuestionTable> getQuestionClickMost();
    /*
    提高点击率
     */
    @Update("update question_table set click_time=#{time} where title=#{title} ")
    public int setClickTime(int time,String title);
    /*
    获取点击率
    */
    @Update("select click_time from question_table where title=#{title}  ")
    public int getClickTime(String title);
    /*
    获取点击率
    */
    @Update("select click_time from question_table where title like '%${title}%'  ")
    public int getClickTimeBy(String title);
    /*
    提高点击率
    */
    @Update("update question_table set click_time=#{time} where title like '%${title}%'  ")
    public int setClickTimeBy(int time,String title);
    /*
    根据分类查询一级标题
     */
    @Select("select * from question_table where classify_title=#{classifyTitle} and classify_level='1'")
    public List<QuestionTable> getQuestionByClassifyTitle(String classifyTitle);
    /*
    根据题目精确查询
     */
    @Select("select * from question_table where title=#{title}")
    public List<QuestionTable> getQuestionByTitle(String title);

    @Insert("insert into question_table(title,answer,classify_title,classify_level)" +
            "value(#{title},#{answer},#{classify_title},classify_level)")
    public int insert(QuestionTable questionTable);

    /*
    查询0级标题
     */
    @Select("select * from question_table where classify_level='0'")
    public List<QuestionTable> getQuestionFirst();

    /*
    关键字模糊查询
    */
    @Select("select * from question_table where classify_level='2' and title like '%${title}%' ")
    public List<QuestionTable> getQuestionByKeyword(String title);

    @Select("select * from question_table where classify_title=#{classify} and title like '%${title}%'  ")
    public List<QuestionTable> getQuestionByClassify(String classify,String title);

}
